﻿using System.Linq;
using System.Windows;

using Screen = System.Windows.Forms.Screen;

namespace Gamey.UI
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public static void FitWindowToLargestScreen(Window window)
        {
            FitWindowToScreen(window, GetLargestScreen());
        }

        static void FitWindowToScreen(Window window, Screen screen)
        {
            window.Top = screen.WorkingArea.Top;
            window.Left = screen.WorkingArea.Left;
            window.Height = screen.WorkingArea.Height;
            window.Width = screen.WorkingArea.Width;
        }

        static Screen GetLargestScreen()
        {
            return Screen.AllScreens.OrderByDescending(s => GetScreenArea(s)).First();
        }

        static int GetScreenArea(Screen screen)
        {
            return screen.WorkingArea.Height * screen.WorkingArea.Width;
        }
    }
}
